package com.xm.queue.util;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 自定义工具类
 * @author wang-xiaoming
 *
 */
public class MyUtil {
	
	private MyUtil() { }
	
	public static final Lock runLock = new ReentrantLock();
	public static final Lock taskLock = new ReentrantLock();
	public static final Condition runCondition = runLock.newCondition();
	public static final Condition taskCondition = taskLock.newCondition();
	
	/**
	 * 默认任务工人数量
	 */
	public static final int DEFAULT_WORKER_COUNT = Runtime.getRuntime().availableProcessors();
//	public static final int DEFAULT_WORKER_COUNT = 1;
	
	/**
	 * 最大任务量
	 */
//	public static final int MAX_TASK = 100000;
	public static final int MAX_TASK = 1;
	
	/**
	 * 缓存线程池超时时长，5秒
	 */
	public static final long DURATION = 5L;
	
	/**
	 * 缓存线程池超时时长单位，单位秒
	 */
	public static final TimeUnit SECONDS = TimeUnit.SECONDS;
	
	/**
	 * 线程任务量统计
	 */
	protected static final Map<String, Integer> finishedTasks = new HashMap<>(16);
	
	public static void main(String[] args) {
		System.out.println("当前系统可用线程数：" + Runtime.getRuntime().availableProcessors());
		System.out.println("任务队列最大任务量：" + MAX_TASK);
		System.out.println("缓存线程池超时时长：" + DURATION);
		System.out.println("缓存线程池超时时长单位：" + SECONDS);
	}
}
